import router from "@/router"
import { useBreadCrumb } from "@/store/breadCrumb"
import { usePermission } from "@/store/permission"


//全局前置守卫(钩子)
router.beforeEach(async (to, from) => {
    //打开进度条
    // NProgress.start()
    let permissStore = usePermission()
    // console.log(to)
    // console.log(from)
    //判断本地的sessionStorage中是否有token,如果有,啥也不干
    let token = sessionStorage.getItem('cxk')
    if (!token) {
        //如果没有
        //1.访问的不是登入页,强行跳转到登入页
        if (to.path !== '/login') {
            return {
                path: '/login'
            }
        }
    }
    //访问的是login页直接放行
})




//全局后置钩子
router.afterEach((to, from) => {
    //关闭进度条
    // NProgress.done()
    let breadCrumbStore = useBreadCrumb()
    breadCrumbStore.$patch(state => {
        state.datas = to.matched
    })
})